﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.Data;

namespace StyleMVVM.LanguageExtensions
{
	public static class IComplexObjectExtensions
	{
		public static T GetFirst<T>(this IComplexObject complexObject) where T : class
		{
			if (complexObject != null)
			{
				if (complexObject is T)
				{
					return (T)complexObject;
				}

				return complexObject.Parent.GetFirst<T>();
			}

			return null;
		}

		public static IComplexObject GetRoot(this IComplexObject complexObject)
		{
			IComplexObject root = complexObject;

			while (root.Parent != null)
			{
				root = root.Parent;
			}

			return root;
		}
	}
}